home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / InterMis.c < prev    next >
C/C++ Source or Header  |  1994-10-03  |  10KB  |  433 lines

  1. #include "WolfDef.h"
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. extern Word NumberIndex;    /* Hack for drawing numbers */
  6. static LongWord BJTime;    /* Time to draw BJ? */
  7. static Word WhichBJ;    /* Which BJ to show */
  8. static LongWord Indexs[3];        /* Offsets to BJ's true shapes */
  9. static Byte *BJPtr;            /* Pointer to BJ's shapes */
  10. static Word ParTime;        /* Par time for level */
  11. static LongWord BonusScore;    /* Additional points */
  12.  
  13. #define BONUSX    353
  14. #define BONUSY    103
  15. #define    TIMEX    353
  16. #define TIMEWIDTH 36
  17. #define    TIMEY    140
  18. #define    TIMEY2    180
  19. #define SCOREX 353
  20. #define SCOREY 332
  21. #define    RATIOX    353
  22. #define    RATIOY    217
  23. #define    RATIOY2    253
  24. #define    RATIOY3    291
  25.  
  26. /**********************************
  27.  
  28.     Draw BJ if needed
  29.     
  30. **********************************/
  31.  
  32. static Rect BJRect = {48,73,48+142,73+131};    /* Rect for BJ's picture */
  33. static void ShowBJ(void) 
  34. {        
  35.     if ((ReadTick()-BJTime) >= 20) {        /* Time to draw a BJ? */
  36.         BJTime = ReadTick();                /* Set the new time */
  37.         if (WhichBJ!=2) {            /* Thumbs up? */
  38.             WhichBJ ^= 1;            /* Nope, toggle breathing */
  39.         }
  40.         DrawShape(73,48,&BJPtr[Indexs[WhichBJ]]);        /* Draw BJ */
  41.         BlastScreen2(&BJRect);                /* Update video */
  42.     }
  43. }
  44.  
  45. /**********************************
  46.  
  47.     Have BJ Breath for a while
  48.     
  49. **********************************/
  50.  
  51. static void BJBreath(Word Delay)
  52. {
  53.     do {
  54.         ShowBJ();
  55.         if (WaitTicksEvent(1)) {
  56.             break;
  57.         }
  58.     } while (--Delay);
  59. }
  60.  
  61. /**********************************
  62.  
  63.     Draw the score 
  64.     
  65. **********************************/
  66.  
  67. static Rect ScoreRect = {SCOREY,SCOREX,SCOREY+22,SCOREX+(12*7)};
  68.  
  69. static void DrawIScore(void) 
  70. {
  71.     SetNumber(gamestate.score,SCOREX,SCOREY,7);        /* Draw the game score */
  72.     BlastScreen2(&ScoreRect);
  73. }
  74.  
  75. /**********************************
  76.  
  77.     Draw the earned bonus
  78.     
  79. **********************************/
  80.  
  81. static Rect BonusRect = {BONUSY,BONUSX,BONUSY+22,BONUSX+(12*7)};
  82. static void DrawIBonus(void)
  83. {
  84.     SetNumber(BonusScore,BONUSX,BONUSY,7);
  85.     BlastScreen2(&BonusRect);
  86. }
  87.  
  88. /**********************************
  89.  
  90.     Draw a time value at the given coords
  91.     
  92. **********************************/
  93.  
  94. static void DrawTime(Word x,Word y,Word time)
  95. {
  96.     Word minutes,seconds;
  97.     Rect TimeRect;
  98.  
  99.     TimeRect.left = x;
  100.     TimeRect.right = x+((12*4)+TIMEWIDTH);
  101.     TimeRect.top = y;
  102.     TimeRect.bottom = y+22;
  103.     
  104.     minutes = time/60;
  105.     seconds = time%60;
  106.     SetNumber(minutes,x,y,2);
  107.     x+=TIMEWIDTH;
  108.     SetNumber(seconds,x,y,2);
  109.     BlastScreen2(&TimeRect);
  110. }
  111.  
  112. /**********************************
  113.  
  114.     Draws a ratio value at the given coords.
  115.     
  116. **********************************/
  117.  
  118. static void DrawRatio(Word x,Word y,Word theRatio)
  119. {
  120.     Rect RatioRect;
  121.     
  122.     RatioRect.top = y;
  123.     RatioRect.left = x;
  124.     RatioRect.bottom = y+22;
  125.     RatioRect.right = x+(3*12);
  126.     SetNumber(theRatio,x,y,3);
  127.     BlastScreen2(&RatioRect);
  128. }
  129.  
  130. /**********************************
  131.  
  132.     RollScore
  133.     Do a Bill-Budgey roll of the old score to the new score,
  134.     not bothering with the lower digit, as you never get less
  135.     than ten for anything.
  136.  
  137. **********************************/
  138.  
  139. static void RollScore(void)
  140. {
  141.     Word i;
  142.  
  143.     do {
  144.         if (BonusScore>1000) {
  145.             i = 1000;
  146.         } else {
  147.             i = BonusScore;
  148.         }
  149.         BonusScore-=i;
  150.         GivePoints(i);
  151.         ShowBJ();
  152.         DrawIScore();
  153.         DrawIBonus();
  154.         PlaySound(SND_MGUN|0x8000);
  155.         if (WaitTicksEvent(6)) {
  156.             GivePoints(BonusScore);    /* Add the final bonus */
  157.             BonusScore=0;
  158.             DrawIScore();
  159.             DrawIBonus();
  160.             break;
  161.         }
  162.     } while (BonusScore);
  163. }
  164.  
  165. /**********************************
  166.  
  167.     RollRatio
  168.     Do a Bill-Budgey roll of the ratio.
  169.  
  170. **********************************/
  171.  
  172. static void RollRatio(Word x,Word y,Word ratio)
  173. {
  174.     Word i;
  175.     Word NoDelay;
  176.  
  177.     i = 0;
  178.     NoDelay = 0;
  179.     while (i<ratio) {
  180.         DrawRatio(x,y,i);
  181.         PlaySound(SND_MGUN|0x8000);
  182.         ShowBJ();
  183.         if (WaitTicksEvent(6)) {    
  184.             NoDelay = 1;
  185.             break;
  186.         }
  187.         i+=10;
  188.     }
  189.     DrawRatio(x,y,ratio);
  190.  
  191.     /* make ding sound */
  192.  
  193.     if (ratio==100) {
  194.         if (!NoDelay) {
  195.             PlaySound(SND_EXTRA);
  196.             WaitTicks(30);
  197.         }
  198.         BonusScore += 10000;
  199.         DrawIBonus();
  200.         if (!NoDelay) {
  201.             BJBreath(60);    /* Breath a little */
  202.         }
  203.     }
  204. }
  205.  
  206. /**********************************
  207.  
  208.     Let's show 'em how they did!
  209.     
  210. **********************************/
  211.  
  212. void LevelCompleted (void)
  213. {
  214.     Word k;
  215.     LongWord *PackPtr;
  216.     Byte *ShapePtr;
  217.     LongWord PackLength;
  218.  
  219. /* setup */
  220.  
  221.     ParTime = MapListPtr->InfoArray[gamestate.mapon].ParTime;
  222.     BonusScore = 0;        /* Init the bonus */
  223.     
  224.     IntermissionHack = TRUE;    /* Hack to keep score from drawing twice */
  225.     NumberIndex = 47;        /* Hack to draw score using an alternate number set */
  226.     NewGameWindow(1);        /* Force 512 mode screen */
  227.     PackPtr = LoadAResource(rIntermission);
  228.     PackLength = PackPtr[0];
  229.     ShapePtr = (Byte *) AllocSomeMem(PackLength);
  230.     DLZSS(ShapePtr,(Byte *) &PackPtr[1],PackLength);
  231.     DrawShape(0,0,ShapePtr);
  232.     FreeSomeMem(ShapePtr);
  233.     ReleaseAResource(rIntermission);
  234.     PackPtr = LoadAResource(rInterPics);
  235.     PackLength = PackPtr[0];
  236.     BJPtr = (Byte *)AllocSomeMem(PackLength);
  237.     DLZSS(BJPtr,(Byte *) &PackPtr[1],PackLength);
  238.     ReleaseAResource(rInterPics);
  239.     memcpy(Indexs,BJPtr,12);        /* Copy the index table */
  240.     
  241.     WhichBJ = 0;        /* Init BJ */
  242.     BJTime = ReadTick()-50;        /* Force a redraw */
  243.     BlastScreen();        /* Draw the screen */
  244.     ShowBJ();            /* Draw BJ */
  245.     StartSong(SongListPtr[1]);    /* Play the intermission song */
  246.     SetAPalette(rInterPal);    /* Set the palette */
  247.     DrawIScore();            /* Draw the current score */
  248.     FlushKeys();            /* Flush the keyboard buffer */
  249.  
  250.     /* First an initial pause */
  251.     
  252.     BJBreath(60);
  253.  
  254.     /* Display Par Time, Player's Time, and show bonus if any. */
  255.  
  256.     if (gamestate.playtime>=(100*60*60UL)) {
  257.         k =(99*60)+59;
  258.     } else {
  259.         k = gamestate.playtime/60;
  260.     }
  261.     DrawTime(TIMEX,TIMEY,k);        /* How much time has elapsed? */
  262.     DrawTime(TIMEX,TIMEY2,ParTime);
  263.  
  264.     if (k < ParTime) {
  265.         k = (ParTime-k) * 50;        /* 50 points per second */
  266.         BonusScore += k;        /* Add to the bonus */
  267.         DrawIBonus();            /* Draw the bonus */
  268.         PlaySound(SND_EXTRA);
  269.         BJBreath(60);            /* Breath a little */
  270.     }
  271.  
  272. /* Show ratios for "terminations", treasure, and secret stuff. */
  273. /* If 100% on all counts, Perfect Bonus! */
  274.  
  275.     k=0;        /* Not perfect (Yet) */
  276.     RollRatio(RATIOX,RATIOY,(gamestate.treasurecount*100)/gamestate.treasuretotal);
  277.     if (gamestate.treasurecount == gamestate.treasuretotal) {
  278.         k++;            /* Perfect treasure */
  279.     }
  280.     RollRatio(RATIOX,RATIOY2,(gamestate.killcount*100)/gamestate.killtotal);
  281.     if (gamestate.killcount == gamestate.killtotal) {
  282.         k++;            /* Perfect kills */
  283.     }
  284.     RollRatio(RATIOX,RATIOY3,(gamestate.secretcount*100)/gamestate.secrettotal);
  285.     if (gamestate.secretcount == gamestate.secrettotal) {
  286.         k++;            /* Perfect secret */
  287.     }
  288.     if (BonusScore) {    /* Did you get a bonus? */
  289.         RollScore();
  290.         BJBreath(60);
  291.     }
  292.     if (k==3) {
  293.         WhichBJ = 2;    /* Draw thumbs up for BJ */
  294.         PlaySound(SND_THUMBSUP);
  295.     }
  296.     do {
  297.         ShowBJ();        /* Animate BJ */
  298.     } while (!WaitTicksEvent(1));        /* Wait for a keypress */
  299.     FreeSomeMem(BJPtr);        /* Release BJ's shapes */
  300.     FadeToBlack();        /* Fade away */
  301.     IntermissionHack = FALSE;        /* Release the hack */
  302.     NumberIndex = 36;            /* Restore the index */
  303. }
  304.  
  305. /**********************************
  306.  
  307.     Handle the intermission screen
  308.     
  309. **********************************/
  310.  
  311. void Intermission (void)
  312. {
  313.     FadeToBlack();
  314.     LevelCompleted();            /* Show the data (Init ParTime) */
  315.     gamestate.globaltime += gamestate.playtime;        /* Add in the playtime */
  316.     gamestate.globaltimetotal += ParTime;    /* Get the par */
  317.     gamestate.globalsecret += gamestate.secretcount;    /* Secrets found */
  318.     gamestate.globaltreasure += gamestate.treasurecount;    /* Treasures found */
  319.     gamestate.globalkill += gamestate.killcount;    /* Number killed */
  320.     gamestate.globalsecrettotal += gamestate.secrettotal;    /* Total secrets */
  321.     gamestate.globaltreasuretotal += gamestate.treasuretotal;    /* Total treasures */
  322.     gamestate.globalkilltotal += gamestate.killtotal;    /* Total kills */
  323.     SetupPlayScreen();        /* Reset the game screen */
  324. }
  325.  
  326. /**********************************
  327.  
  328.     Okay, let's face it: they won the game.
  329.     
  330. **********************************/
  331.  
  332. void VictoryIntermission (void)
  333. {
  334.     FadeToBlack();
  335.     LevelCompleted();
  336. }
  337.  
  338. /**********************************
  339.  
  340.     Show player the game characters
  341.     
  342. **********************************/
  343.  
  344. #define NUMCAST 12
  345. Word caststate[NUMCAST] = {
  346. ST_GRD_WLK1, ST_OFC_WLK1, ST_SS_WLK1,ST_MUTANT_WLK1,
  347. ST_DOG_WLK1, ST_HANS_WLK1, ST_SCHABBS_WLK1, ST_TRANS_WLK1,
  348. ST_UBER_WLK1, ST_DKNIGHT_WLK1,ST_MHITLER_WLK1, ST_HITLER_WLK1};
  349.  
  350. #if 0
  351. char *casttext[NUMCAST] = { /* 28 chars max */
  352. "GUARD",
  353. "OFFICER",
  354. "ELITE GUARD",
  355. "MUTANT",
  356. "MUTANT RAT",
  357. "HANS GROSSE",
  358. "DR. SCHABBS",
  359. "TRANS GROSSE",
  360. "UBERMUTANT",
  361. "DEATH KNIGHT",
  362. "MECHAMEISTER",
  363. "STAATMEISTER"
  364. };
  365. #endif
  366.  
  367. void CharacterCast(void)
  368. {
  369.     Word Enemy,count, cycle;
  370.     Word up;
  371.     state_t *StatePtr;
  372.  
  373. /* reload level and set things up */
  374.  
  375.     gamestate.mapon = 0;        /* First level again */
  376.     PrepPlayLoop();                /* Prepare the system */
  377.     viewx = actors[0].x;        /* Mark the starting x,y */
  378.     viewy = actors[0].y;
  379.  
  380.     topspritescale = 32*2;
  381.  
  382. /* go through the cast */
  383.  
  384.     Enemy = 0;
  385.     cycle = 0;
  386.     do {
  387.         StatePtr = &states[caststate[Enemy]];        /* Init the state pointer */
  388.         count = 1;            /* Force a fall through on first pass */
  389.         up = FALSE;
  390.         for (;;) {
  391.             if (++cycle>=60*4) {        /* Time up? */
  392.                 cycle = 0;                /* Reset the clock */
  393.                 if (++Enemy>=NUMCAST) {    /* Next bad guy */
  394.                     Enemy = 0;            /* Reset the bad guy */
  395.                 }
  396.                 break;
  397.             }
  398.             if (!--count) {
  399.                 count = StatePtr->tictime;
  400.                 StatePtr = &states[StatePtr->next];
  401.             }
  402.             topspritenum = StatePtr->shapenum;    /* Set the formost shape # */
  403.             RenderView();        /* Show the 3d view */
  404.             WaitTicks(1);        /* Limit to 15 frames a second */
  405.             ReadSystemJoystick();    /* Read the joystick */
  406.             if (!joystick1 && !up) {
  407.                 up = TRUE;
  408.                 continue;
  409.             }
  410.             if (!up) {
  411.                 continue;
  412.             }
  413.             if (!joystick1) {
  414.                 continue;
  415.             }
  416.             if (joystick1 & (JOYPAD_START|JOYPAD_A|JOYPAD_B|JOYPAD_X|JOYPAD_Y)) {
  417.                 Enemy = NUMCAST;
  418.                 break;
  419.             }
  420.             if ( (joystick1 & (JOYPAD_TL|JOYPAD_LFT)) && Enemy >0) {
  421.                 Enemy--;
  422.                 break;
  423.             }
  424.             if ( (joystick1 & (JOYPAD_TR|JOYPAD_RGT)) && Enemy <NUMCAST-1) {
  425.                 Enemy++;
  426.                 break;
  427.             }
  428.         }
  429.     } while (Enemy < NUMCAST);    /* Still able to show */
  430.     StopSong();        /* Stop the music */
  431.     FadeToBlack();    /* Fade out */
  432. }
  433.